Skip to content

Fix superblock IO error handling and add footer validation#889

Open
xiaoxichen wants to merge 2 commits into
eBay:stable/v7.xfrom
xiaoxichen:fix-superblock-io-error
Open

Fix superblock IO error handling and add footer validation#889
xiaoxichen wants to merge 2 commits into
eBay:stable/v7.xfrom
xiaoxichen:fix-superblock-io-error

Conversation

@xiaoxichen

Copy link
Copy Markdown
Collaborator

This change improves superblock error handling and integrity checking:

  • Fail fast on IO errors during superblock read instead of treating them as fresh/unformatted disks
  • Add footer superblock validation for HDD devices to detect corruption
  • Check header and footer write errors independently to prevent silent failures
  • Add comprehensive unit tests covering all error scenarios

Changes:

  • read_first_block(): Now throws std::system_error on IO errors instead of returning garbage data
  • write_super_block(): Separately validates header and footer writes with independent error checking
  • sanity_check(): New method that validates footer consistency on HDD devices by comparing header and footer superblocks using full memcmp
  • Added 6 unit tests covering IO errors, corruption detection, and footer validation scenarios

Use release assert instead of exceptions for superblock IO errors

Per review feedback, replace exception throws with HS_REL_ASSERT for all superblock IO errors to ensure immediate crash on failure:

  • read_first_block(): Use HS_REL_ASSERT instead of throwing std::system_error
  • sanity_check(): Use HS_REL_ASSERT for header/footer read errors and mismatch
  • Update tests from ASSERT_THROW to ASSERT_DEATH to verify crash behavior

@xiaoxichen

Copy link
Copy Markdown
Collaborator Author

@JacksonYao287 this is a replacement PR for #866

could you please take a review

@xiaoxichen xiaoxichen requested a review from JacksonYao287 June 4, 2026 13:41
Comment thread src/lib/device/physical_dev.cpp
@xiaoxichen xiaoxichen force-pushed the fix-superblock-io-error branch from 8ef07a3 to 7bf160a Compare June 5, 2026 10:27
This change improves superblock error handling and integrity checking:

- Fail fast on IO errors during superblock read instead of treating them as
  fresh/unformatted disks
- Add footer superblock validation for HDD devices to detect corruption
- Check header and footer write errors independently to prevent silent failures
- Add comprehensive unit tests covering all error scenarios

Changes:
- read_first_block(): Now throws std::system_error on IO errors instead of
  returning garbage data
- write_super_block(): Separately validates header and footer writes with
  independent error checking
- sanity_check(): New method that validates footer consistency on HDD devices
  by comparing header and footer superblocks using full memcmp
- Added 6 unit tests covering IO errors, corruption detection, and footer
  validation scenarios

Use release assert instead of exceptions for superblock IO errors

Per review feedback, replace exception throws with HS_REL_ASSERT for all
superblock IO errors to ensure immediate crash on failure:

- read_first_block(): Use HS_REL_ASSERT instead of throwing std::system_error
- sanity_check(): Use HS_REL_ASSERT for header/footer read errors and mismatch
- Update tests from ASSERT_THROW to ASSERT_DEATH to verify crash behavior
@xiaoxichen xiaoxichen force-pushed the fix-superblock-io-error branch from 7bf160a to 6dd7079 Compare June 5, 2026 10:29
@xiaoxichen

Copy link
Copy Markdown
Collaborator Author

@JacksonYao287 comment addressed

JacksonYao287
JacksonYao287 previously approved these changes Jun 5, 2026
On first boot (format_devices path), all devices have invalid headers on
disk when PhysicalDev is constructed — before write_super_block is called.
The original code blindly memcmp'd header vs footer on garbage data,
causing a crash on HDD devices where mirror_super_block=1.

In load_devices, a device with an invalid header goes to pdevs_to_format
and then format_single_device. At that point m_first_blk_hdr (and thus
m_pdev_info.system_uuid) is already populated from other valid devices in
the cluster. So if the footer on disk is valid and its system_uuid matches,
it means the footer survived but the header was corrupted — not a fresh
device. If the footer uuid does not match (or footer is invalid), it is
leftover/garbage data and safe to treat as first boot.

New logic:
- Header valid: compare header and footer as before
- Header invalid, footer valid + uuid matches cluster: header corruption, assert
- Otherwise: first boot / leftover data, skip validation
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 45.00000% with 11 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (stable/v7.x@ef9ab9d). Learn more about missing BASE report.

Files with missing lines Patch % Lines
src/lib/device/physical_dev.cpp 42.10% 0 Missing and 11 partials ⚠️
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.
Additional details and impacted files
@@              Coverage Diff               @@
##             stable/v7.x     #889   +/-   ##
==============================================
  Coverage               ?   48.35%           
==============================================
  Files                  ?      110           
  Lines                  ?    12971           
  Branches               ?     6235           
==============================================
  Hits                   ?     6272           
  Misses                 ?     2565           
  Partials               ?     4134           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants